
package tests.laurens;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import combat.dudes.DudesFunctions;


/**
 * @author Laurens Andriessen
 * @version 1.0
 */
public class PolyPicker extends JFrame {

	public PolyPicker() {
		super("PolyPicker 2011 - by Laurens Andriessen");
		setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				System.exit(0);
			}
		});

		Graphics2D g = (Graphics2D) getGraphics();
		Image image = DudesFunctions.File.getImage("land.gif");
		g.drawImage(image, 0, 0, this);

		this.addMouseListener(new MouseListener() {

			private Polygon poly = new Polygon();
			@Override
			public void mouseClicked(MouseEvent m) {}

			@Override
			public void mouseEntered(MouseEvent m) {}

			@Override
			public void mouseExited(MouseEvent m) {}

			@Override
			public void mousePressed(MouseEvent m) {}

			@Override
			public void mouseReleased(MouseEvent m) {
				System.out.println("poly.addPoint(" + m.getX() + ", " + m.getY() + ");");

				Graphics2D g = (Graphics2D) getGraphics();
				g.clearRect(0, 0, getWidth(), getHeight());
				g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Set AA on for shapes
				poly.addPoint(m.getX(), m.getY());
				g.fillPolygon(poly);

			}

		});

		setVisible(true);
	}
	public static void main(String[] args) {
		new PolyPicker();
	}


}
